package 递归;

public class Demo {

	public static void main(String[] args) {
		//whileDemo();
		//whileDemoIfElse();
		int i = fib(3);
		//int i = jicheng(5);
		System.out.println(i);
	}
	/*
	 * 循环 while
	 */
	static void whileDemo(){
		int a = 1;
		while(a < 10){
			System.out.println(a);
			a+=2;
		}
	}
	static void whileDemoIfElse(){
		int a =1;
		while(a < 7){
			if(a % 2 == 0){
				System.out.println(a+",is even");
			}else{
				System.out.println(a+",is odd");
			}
			a+=1;
		}
	}
	
	/**
	 * 递归求裴波纳契数列
	 * @param n
	 * @return
	 */
	static int fib(int n){
		if(n == 0){
			return 0;
		}else if(n == 1){
			return 1;
		}else{
			return fib(n-1)+fib(n-2);
		}
	}
	
	/**
	 * 阶乘 1*2*3*4*5。。。
	 * @param n
	 * @return
	 */
	static int jicheng(int n){
		if(n == 1){
			return 1;
		}else{
			return n * jicheng(n-1);
		}
	}
}
